package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface ShoppingCartMapper {

    /**
     * 插入购物车数据
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart (name, user_id, dish_id, setmeal_id, dish_flavor, number, amount, image, create_time) " +
            " values (#{name},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{image},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    ShoppingCart shopByShop(ShoppingCart shoppingCart);

    List<ShoppingCart> list(ShoppingCart shoppingCart);
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumber(ShoppingCart aNew);
    @Delete("delete From shopping_cart where id = #{id}")
    void deleteById(Long id);
    @Delete("delete From shopping_cart where user_id = #{userId}")
    void clean(Long userId);
//    // 根据ID删除购物车记录
//    @Delete("DELETE FROM shopping_cart WHERE id = #{id}")
//    void deleteById(Long id);
//
//    // 更新购物车记录
//    @Update("UPDATE shopping_cart SET name = #{name}, userId = #{userId}, dishId = #{dishId}, setmealId = #{setmealId}, " +
//            "dishFlavor = #{dishFlavor}, number = #{number}, amount = #{amount}, image = #{image}, createTime = #{createTime} WHERE id = #{id}")
//    void update(ShoppingCart shoppingCart);
//
//    // 根据ID查询购物车记录
//    @Select("SELECT * FROM shopping_cart WHERE id = #{id}")
//    ShoppingCart getById(Long id);
//
//    // 查询所有购物车记录
//    @Select("SELECT * FROM shopping_cart")
//    List<ShoppingCart> listAll();

    // 根据用户ID查询购物车记录
    @Select("SELECT * FROM shopping_cart WHERE user_id = #{userId}")
    List<ShoppingCart> listByUserId(Long userId);
}